Move JSON stores to source generation (trim-prep)#29
Merged
Conversation
Add StoreJsonContext (source-gen JsonSerializerContext) for SnipStoreDocument and AppConfig, and switch JsonSnipStore/JsonSettingsStore onto the generated metadata. This removes the IL2026 reflection-serializer trim warnings and is AOT-friendlier. The wire format is preserved exactly: enum names are pinned with [JsonStringEnumMemberName] to the previous camelCase output, and StoreJsonCompatibilityTests assert the source-gen output is byte-identical to the old reflection serializer (and that legacy JSON round-trips), so existing store/settings files keep loading. PublishTrimmed stays off: source-gen cleared IL2026, but a trimmed WinUI publish still fails IL2104 on Microsoft.Windows.SDK.NET, WinRT.Runtime and Jdenticon (not trim-safe). Verdict in the csproj comment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task #9 ("Re-enable PublishTrimmed"), handled per the agreed "land the safe part, verdict on the flip" plan.
What landed (the safe, valuable part)
StoreJsonContext— a source-generatedJsonSerializerContextforSnipStoreDocumentandAppConfig.JsonSnipStore/JsonSettingsStorenow serialise via the generated metadata instead of the reflection-basedJsonSerializer.Serialize/Deserialize<T>, removing the IL2026 trim warnings and making serialization AOT-friendlier.[JsonStringEnumMemberName]to the previous camelCase output ("choice","dark","hideToTray","control"…).StoreJsonCompatibilityTestsassert the source-gen output is byte-identical to the old serializer for both document and config, and that legacy JSON round-trips through the new context — so existing on-disk stores keep loading. (Fully verified on Linux.)Verdict on the flip (PublishTrimmed stays OFF)
Source-gen cleared IL2026, but a trimmed Release publish on the Windows agent still fails IL2104 on three assemblies that aren't annotated trim-safe:
Microsoft.Windows.SDK.NETWinRT.RuntimeJdenticonSilencing IL2104 wouldn't make trimming safe — the WinRT interop layer uses reflection, so full trimming risks runtime breakage a build can't catch. A WinUI head can't be fully trimmed without partial-trim (which only trims our own tiny assemblies → negligible savings). So
PublishTrimmedstays off, with the reasoning recorded in the csproj. Revisit only if the WinAppSDK/WinRT assemblies ship trim annotations.Net: the IL2026 half of the original blocker is resolved and the stores are source-gen'd; the size win isn't achievable yet for reasons outside our code.
Tests
StoreJsonCompatibilityTests(byte-identical document + config; legacy round-trip). Full suite: 140 passing.🤖 Generated with Claude Code